package com.hzdl.car.controller;

import com.hzdl.car.service.CustomerService;
import com.hzdl.car.service.RentService;
import com.hzdl.car.util.HzdlResultJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("stat")
public class StatController {
    @Resource
    private CustomerService customerService;
    @Resource
    private RentService rentService;
    //客户地区统计页面
 @RequestMapping("findCustomerStat")
    public String findCustomerStat(){
     return "stat/customerStat";
 }
  //客户地区统计
    @RequestMapping("findCustomerAddress")
    @ResponseBody
    public HzdlResultJson findCustomerAddress(){
     try {
         return HzdlResultJson.ok(customerService.findCustomerAddress());
     }catch (Exception e){
         return HzdlResultJson.error(-1,e.getMessage());
     }
    }
    //显示业务员销售页面
    @RequestMapping("findOpenNameStat")
    public  String findOpenNameStat(){
     return "stat/openNameStat";
    }
    @RequestMapping("priceByYear")
    @ResponseBody
    public HzdlResultJson priceByYear(@RequestParam(value = "year") Integer year){
     try {
         return HzdlResultJson.ok(rentService.findPriceByYear(year));
     }catch (Exception e){
         return HzdlResultJson.error(-1,e.getMessage());
     }
    }
    //显示年度月销售额页面
    @RequestMapping("findCompanyStat")
    public String findCompanyStat(){
     return "/stat/companyStat";
    }
    @RequestMapping("companyPriceByYear")
    @ResponseBody
    public HzdlResultJson companyPriceByYear(@RequestParam(value = "year") Integer year){
     try {
         return HzdlResultJson.ok(rentService.companyPriceByYear(year));
     }catch (Exception e){
         return HzdlResultJson.error(-1,e.getMessage());
     }
    }
}
